package com.to.aboomy.bannersample.pagetransformer;

import com.to.aboomy.banner.BannerViewPager;
import ohos.agp.components.Component;

/**
 * @author xujianhong
 * @since 2021-08-05
 */
public class RotateDownTransformer implements BannerViewPager.PageTransformer {

    @Override
    public void transformerPage(BannerViewPager.PageType pageType, Component page, float offset, float offsetPixels) {

        float width = (float) page.getWidth();
        float height = (float) page.getHeight();

        switch (pageType) {
            case PREVIOUS:
                if (offsetPixels < 0) {
                    offset = 1 - offset;
                    float rotation = 18.75F * offset;
                    page.setPivotX(width * 0.5F);
                    page.setPivotY(height);
                    page.setRotation(-rotation);
                }
                break;
            case CURRENT:
                float rotation = 18.75F * offset;
                page.setPivotX(width * 0.5F);
                page.setPivotY(height);
                if (offsetPixels >= 0) {
                    page.setRotation(-rotation);
                } else {
                    page.setRotation(rotation);
                }
                break;

            case NEXT:
                offset = 1 - offset;
                float rotation2 = 18.75F * offset;
                page.setPivotX(width * 0.5F);
                page.setPivotY(height);
                if (offsetPixels >= 0) {
                    page.setRotation(rotation2);
                } else {
                    page.setRotation(-rotation2);
                }

                break;

            case OTHER:
                page.setPivotX(1F);
                page.setPivotY(1F);
                page.setRotation(0F);
                break;
        }
    }
}
